package com.fps.web.dao.impl;
import org.springframework.stereotype.Repository;

import com.fpswork.core.exception.exception.BusinessException;
import com.fpswork.core.model.PageEntity;
import com.fpswork.datamodel.basedao.BaseDao;
import com.fpswork.util.BeanUtils;
import com.fpswork.util.StringUtil;
import com.fps.web.dao.BasemenuDao;
import com.fps.web.model.Basemenu;
@Repository 
public class BasemenuDaoImpl extends BaseDao implements BasemenuDao{
    
	public PageEntity queryBasemenuList(PageEntity pageEntity)  throws BusinessException{
		String sql="select * from basemenu where 1=1";
		if(pageEntity.getSearch()!=null&&StringUtil.isNotEmpty(pageEntity.getSearch().get("menuname"))){
			sql+=" and basemenu.menuname='"+pageEntity.getSearch().get("menuname")+"' ";
		}
		pageEntity.setSql(sql);
		return  this.queryForPageEntity(pageEntity);
	}
	public Basemenu queryBasemenuByID(String id)  throws BusinessException{
		return  this.get(Basemenu.class, id);
	}
	
	public Basemenu addBasemenu(Basemenu basemenu)  throws BusinessException{
		//校验是否为空
		if(basemenu==null){
			throw new BusinessException("传入数据为空！");
		}
		if(StringUtil.isEmpty(basemenu.getId())){
			this.save(basemenu);
		}else{
			throw new BusinessException("已存在数据！");
		}
		return basemenu;
	}
	public Basemenu updateBasemenu(Basemenu basemenu)  throws BusinessException{
		Basemenu basemenu1= this.get(Basemenu.class, basemenu.getId());
		if(basemenu1==null||StringUtil.isEmpty(basemenu1.getId())){
	 		throw new BusinessException("没有找到数据！");
		}else{
			BeanUtils.copyProperties(basemenu1, basemenu);
			this.update(basemenu1);
		}
		return basemenu1;
	}
	public Boolean deleteBasemenu(Basemenu basemenu)  throws BusinessException{
		this.delete(this.get(Basemenu.class, basemenu.getId()));
		
		return true;
	}
}
